using System;
using System.Collections;
using UnityEngine;
using UnityScript.Lang;

[Serializable]
public class WaypointsHolder : MonoBehaviour
{
	public Color color;

	public Waypoint[] waypoints;

	public bool colorizeWaypoints;

	public WaypointsHolder()
	{
		color = new Color(0f, 1f, 0f, 0.5f);
		colorizeWaypoints = true;
	}

	public void Start()
	{
		if (waypoints.Length == 0)
		{
			waypoints = (Waypoint[])new UnityScript.Lang.Array(transform.childCount).ToBuiltin(typeof(Waypoint));
			Component[] componentsInChildren = GetComponentsInChildren(typeof(Waypoint));
			int num = 0;
			int i = 0;
			Component[] array = componentsInChildren;
			for (int length = array.Length; i < length; i++)
			{
				waypoints[num] = (Waypoint)array[i];
				num++;
			}
		}
	}

	public void AddWaypoint()
	{
		if (waypoints.Length == 0)
		{
			waypoints = (Waypoint[])new UnityScript.Lang.Array(0).ToBuiltin(typeof(Waypoint));
		}
		UnityScript.Lang.Array array = new UnityScript.Lang.Array((IEnumerable)waypoints);
		array.length++;
		waypoints = (array.ToBuiltin(typeof(Waypoint)) as Waypoint[]);
		if (waypoints.Length > 1)
		{
			waypoints[waypoints.Length - 1] = new Waypoint();
		}
	}

	public void DeleteWaypoint()
	{
		if (waypoints.Length > 0)
		{
			UnityScript.Lang.Array array = new UnityScript.Lang.Array((IEnumerable)waypoints);
			array.length--;
			waypoints = (array.ToBuiltin(typeof(Waypoint)) as Waypoint[]);
		}
	}

	public void OnDrawGizmos()
	{
		Gizmos.color = color;
		if (waypoints.Length <= 0)
		{
			return;
		}
		for (int i = 0; i < waypoints.Length - 1; i++)
		{
			if ((bool)waypoints[i] && (bool)waypoints[i + 1])
			{
				Gizmos.DrawLine(waypoints[i].gameObject.transform.position, waypoints[i + 1].gameObject.transform.position);
				if (colorizeWaypoints)
				{
					waypoints[i + 1].color = color;
				}
			}
		}
	}

	public void Main()
	{
	}
}
